package com.adee.java;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class Test008_BinaryTree {
    public static void main(String[] args) {

    }

    public static void test01() {
        BinaryTreeNode<Integer> node = new BinaryTreeNode<>(10, null);
    }
}

abstract class TreeNode<E> {
    TreeNode parent;
    E element;
    List<TreeNode> children = initChidrenList();

    protected abstract List<TreeNode> initChidrenList();

    public TreeNode() {

    }
    public TreeNode(E e, TreeNode<E> parent) {
        this.element = e;
        this.parent = parent;
    }

    // 遍历子节点
    public void forEachChild(Consumer<TreeNode> consumer) {
        this.children.forEach(consumer);
    }
}

class BinaryTreeNode<E> extends TreeNode<E> {

    public BinaryTreeNode(E e, TreeNode<E> parent) {
        super(e, parent);
    }

    @Override
    protected List<TreeNode> initChidrenList() {
        return new ArrayList<>(2);
    }

}
